home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cnews004.zip / FF.ZIP / FINDENTR.C < prev    next >
Text File  |  1987-07-02  |  2KB  |  72 lines

  1. #include <dos.h>
  2. #include "dostype.h"
  3.  
  4. extern void get_DTA(unsigned *,unsigned *),
  5.             set_DTA(unsigned, unsigned);
  6.  
  7. findentr(DTA, search_name, s_attr)
  8. struct DTA_STRUCT *DTA; /* NULL to use default DTA */
  9. char *search_name;
  10. int s_attr; /* permitted attributes (use for H,S,D) */
  11. {
  12. char far *far_sn=search_name;
  13. struct DTA_STRUCT far *far_DTA=DTA;
  14. union REGS inregs;
  15. struct SREGS segregs;
  16. unsigned save_DTA_SEG;
  17. unsigned save_DTA_OFF;
  18.  
  19. if (DTA)
  20.   {
  21.   /* save current DTA address */
  22.   get_DTA(&save_DTA_SEG,&save_DTA_OFF);
  23.   /* set DTA address to argument structure */
  24.   set_DTA(FP_SEG(far_DTA),FP_OFF(far_DTA));
  25.   }
  26.  
  27. /* Find first match file */
  28. inregs.h.ah=0x4e;
  29. inregs.x.cx=s_attr;
  30. segregs.ds=FP_SEG(far_sn);
  31. inregs.x.dx=FP_OFF(far_sn);
  32. int86x(0x21,&inregs,&inregs,&segregs);
  33.  
  34. if (DTA)
  35.   /* restore DTA address */
  36.   set_DTA(save_DTA_SEG,save_DTA_OFF);
  37.  
  38. /* return result */
  39. if (inregs.x.cflag) return (inregs.x.ax);
  40. else return 0;
  41. }
  42.  
  43. findnext(DTA)
  44. struct DTA_STRUCT *DTA; /* NULL to use default DTA */
  45. {
  46. struct DTA_STRUCT far *far_DTA=DTA;
  47. union REGS inregs;
  48. struct SREGS segregs;
  49. unsigned save_DTA_SEG;
  50. unsigned save_DTA_OFF;
  51.  
  52. if (DTA)
  53.   {
  54.   /* save current DTA address */
  55.   get_DTA(&save_DTA_SEG,&save_DTA_OFF);
  56.   /* set DTA address to argument structure */
  57.   set_DTA(FP_SEG(far_DTA),FP_OFF(far_DTA));
  58.   }
  59.  
  60. /* Find next entry */
  61. inregs.h.ah=0x4f;
  62. int86(0x21,&inregs,&inregs);
  63.  
  64. if (DTA)
  65.   /* restore DTA address */
  66.   set_DTA(save_DTA_SEG,save_DTA_OFF);
  67.  
  68. /* return result */
  69. if (inregs.x.cflag) return (inregs.x.ax);
  70. else return 0;
  71. }
  72.